﻿#ifndef CAMERAMANAGE_H
#define CAMERAMANAGE_H

#include <QObject>
#include <QLabel>
#include <QMap>
#include <QThread>
#include "CameraBase.h"
#include "CameraManageWidget.h"
#include "CameraStatusWidget.h"

class CameraManage : public QObject
{
    Q_OBJECT
public:
    explicit CameraManage(QObject *parent = nullptr);
    QWidget* getCamStatusWidget(){return wgtCamStatus;}
    QWidget* getCameraManageWidget(){return mCameraManageWidget;}
    QMap<QString, CameraBase*> getCamAll(){return mMapCam;}
    void setConfigWriteOneFunc(void (*func)(const CameraConfig& config));
    void setConfigReadAllFunc(QMap<QString, CameraConfig> (*func)());
    void setConfigReadOneFunc(CameraConfig (*func)(QString camName));
    void startWorker();
    void checkCameraStatus();
    void initCameraAll();
    void initWgtCamStatus();
    void initCameraManageWidget();

public slots:
    void onAddOne(const CameraConfig& config);
    void onDeleteOne(const QString& name);
    void onConfigChanged(const CameraConfig& config);
signals:
    void sigCameraStatus(bool isOnLine);
    void sigSetCameraConfig(const CameraConfig& config);

private:
    void initCameraOne(CameraConfig config);

private:
    void (*configWriteOne)(const CameraConfig& config);
    QMap<QString, CameraConfig> (*configReadAll)();
    CameraConfig (*configReadOne)(QString camName);
    void (*configRemoveOne)(QString camName);
private:
    QMap<QString, CameraBase*> mMapCam;
    QMap<QString, QThread*> mMapCamThread;
    QMap<QString, bool> mMapCameraStart;

    CameraStatusWidget* wgtCamStatus;

    CameraManageWidget* mCameraManageWidget;

};

#endif // CAMERAMANAGE_H
